package org.shushan.web.demo.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Getter;
import lombok.Setter;
import org.shushan.framework.core.resp.Result;
import org.shushan.framework.web.base.CrudControllerV2;
import org.shushan.web.demo.entity.MybatisTest;
import org.shushan.web.demo.request.MybatisTestDto;
import org.shushan.web.demo.request.MybatisTestPage;
import org.shushan.web.demo.response.MybatisTestVo;
import org.shushan.web.demo.service.MybatisTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * (TUser)控制层
 * @author zhigang.li
 * @email 2429967859@qq.com
 * @since 2023-09-16 22:25:41
 */
@RestController
@Tag(name = "TUserController", description = "TUserController")
@RequestMapping("mybatisTest")
public class MybatisTestController extends CrudControllerV2<MybatisTestPage, MybatisTestDto, MybatisTestVo, Long, MybatisTest, MybatisTestService> {

    //todo list 和page 接口的 swagger文档不对


    @Autowired
    MybatisTestService mybatisTestService;

    @Operation(description = "根据id查询")
    @GetMapping({"{id}"})
    @Parameters({
            @Parameter(name = "id", description = "主键id", required = true)
    })
    @Override
    public Result<MybatisTestVo> get(@NotNull @PathVariable("id") Long id) {
        Result<MybatisTestVo> tUserVoResult = super.get(id);
        //测试缓存删除
//        ((BaseCacheService) tUserService).flushCaches();
        return tUserVoResult;
    }


    @Operation(description = "测试注入参数")
    @GetMapping({"testParamInjection"})
    public Result<Long> testParamInjection(@RequestParam Long studyId) {
        return Result.ok(studyId);
    }


    @Operation(description = "测试注入参数2")
    @GetMapping({"/testParamInjection2"})
    public Result<Long> testParamInjection2(@RequestBody Test test) {
        return Result.ok(test.getStudyId());
    }

    @Getter
    @Setter
    @Schema(name = "Test")
    static class Test {
        @Schema(name = "studyId")
        private Long studyId;
    }


}

